package com.eureka.client;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.eureka.client.api.user.UserService;
import com.eureka.client.mobile.user.User;

@RestController
@RequestMapping("/EurekaClient")
public class EurekaClientController {
	
	@Autowired
	private UserService userService;
	
	  @Value("${server.port}")
	    String port;
	 @RequestMapping("/hi")
	    public String home(@RequestParam String name) {
	        return "hi " + name + ",i am from port:" + port;
	    }
	 
	 
	 /**
	  * 
	  * 查询用户名
	  */
	 
	    @RequestMapping("/queryUser")
	    public Map<String,Object> queryUser(@RequestParam String username) {
		 
		 Map<String,Object> map = new HashMap<String,Object>();
		 
		 User  user = null;
		 
		 try {
			 
			 user = new User();
			 
			  user.setUsername(username);
			 
			  user =  userService.queryUser(user);
			  
			     map.put("messageCode", "001");
				 
				 map.put("message", "查询成功!");
				 
				 map.put("user", user);
				 
				 return map;
			 
		 }catch(Exception ex){
			 
			 map.put("messageCode", "003");
			 
			 map.put("message", "网络异常，请稍后!");
			 
			 return map;
			 
		 }
		 
	    }

}
